import 'package:flutter/material.dart';
import 'package:github_client_app/blocs/bloc_exports.dart';
import 'package:github_client_app/screens/add_task_screen.dart';
import 'package:github_client_app/widget/my_drawer.dart';
import 'package:github_client_app/widget/tasks_list.dart';

class TasksScreen extends StatelessWidget {
  const TasksScreen({Key? key}) : super(key: key);

  void addTask(BuildContext context) {
    showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return SingleChildScrollView(
          child: Container(
            padding: EdgeInsets.only(
                bottom: MediaQuery.of(context).viewInsets.bottom),
            child: const AddTaskScreen(),
          ),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("task app"),
        actions: [
          IconButton(
            onPressed: () {
              addTask(context);
            },
            icon: const Icon(Icons.add),
          ),
        ],
      ),
      drawer: const MyDrawer(),
      body: BlocBuilder<TasksBloc, TasksState>(
        builder: (context, state) {
          return Column(
            children: [
              Chip(
                label: Text("task app--${state.allTasks.length}"),
              ),
              TasksList(tasks: state.allTasks)
            ],
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          addTask(context);
        },
        tooltip: "add task",
        child: const Icon(Icons.add),
      ),
    );
  }
}
